<?php
//-----------------------
// PHP Cool Bot 1.5.2
// by NarKoZ@jabber.ru
//-----------------------

//Errors off
error_reporting(E_ALL & ~E_NOTICE);
//Script time no limit
set_time_limit (0);

//INCLUDE XMPPHP LIB
include("xmpp.php");

//INCLUDE CONFIG
include("config.php");

//PRESENT ARRAY SET 0
$present[0]=' ';
$roles[0]=' ';
$no_spamm[0]=' ';


//FUNCTIONS---------------------------------------------------------------------
//pass function
function genPwd($length = 10){
$pass='';
    $pass = str_repeat(' ',$length);
    return preg_replace_callback('#.#','randSymbol',$pass);
}

function randSymbol(){
    $str = 'qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM0123456789';
    return $str[mt_rand(0,strlen($str)-1)];
}

//CONNECTION-OPTIONS
//-----------------server-----port----user--------pass-------res--------server-------loging------
$conn = new XMPP($cbot_jid_server, 5222, $cbot_jid_nick, $cbot_jid_pass, $cbot_jid_resource.rand (1, 100), $cbot_jid_server, $printlog=True, $loglevel=LOGGING_INFO);

//-----------------------
$conn->addHandler ('iq','jabber:client','income_iq');

$conn->connect();
while(!$conn->disconnected) {
	$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start'));
	foreach($payloads as $event) {
		$pl = $event[1];
		switch($event[0]) {

case 'message':
//sleep (rand(0, 1));

//check-from-message
$msg_type = $pl['type'];
$tmp = explode("/", $pl['from']);
$from_user = $tmp[1];
$from_conf = $pl['from'];
if ($msg_type=='chat') $from_user = '';
//if ($msg_type=='error') $msg_type='groupchat';
if ($msg_type=='groupchat')
{
$from_conf = $tmp[0];
$from_user = $tmp[1];
}


//check owner-------------------------
$in_arr = explode("/", $pl['from']);
$isowner='no';
if(strtolower($in_arr[0]) == strtolower($owner)) $isowner ='yes';

//check admin-------------------------
$in_arr = explode("/", $pl['from']);
$isadmin ='no';
if(in_array(strtolower($in_arr[0]), $admins)){$isadmin ='yes';}

//check-moderator---------------------
$key = array_search($pl['from'], $roles);
$ismoder = 'no';

if ($key)
{if ($roles[$key+2] == 'moderator') $ismoder = 'yes';
}


//check ban
if ($pl['type'] = 'chat')
{
$tmp = explode("/", $pl['from']);
$ban_jid = $tmp[0];
$ban_jid = strtolower($ban_jid);
$key = array_search($ban_jid, $ban_list);         // $key = 1;
}

if ($pl['type'] = 'groupchat')
{
//$ban_jid = $pl['from'];
}

$ban_jid = strtolower($ban_jid);
$key = array_search($ban_jid, $ban_list);         // $key = 1;
$banned = 'no';
if ($key > 0) $banned = 'yes';

if ($banned == 'no')
//if ($pl['from'] != $cbot_jid_nick.'@'.$cbot_jid_server.'/'.$cbot_jid_resource)
{

if ($pl['type']=='iq')
{//$conn->message('narkoz@jabber.ru', $body=$pl['info'], $type='chat');
}



//SET LANG BY CONF/USER

	if ($msg_type=='groupchat')
		{
        $key = array_search($from_conf, $all_conf);         // $key = 1;
        if ($key>0)
        {
        $lang = $all_conf[$key+1];
        }
        else {$lang='en';}
	  	}

	if ($msg_type=='chat')
		{
        $key = array_search($from_conf, $jid_all_users);     // $key = 1;
        if ($key>0)
        {
        $lang = $jid_all_users[$key+1];
        }
        else {$lang='en';}
	  	}

//DEFAULT LANGUAGE SET
if ($lang == 'ru') $LANG_OUT = $LANG_RU;
if ($lang == 'ru2') $LANG_OUT = $LANG_RU2;
if ($lang == 'ua') $LANG_OUT = $LANG_UA;
if ($lang == 'en') $LANG_OUT = $LANG_EN;
if ($lang == 'id') $LANG_OUT = $LANG_ID;

$wrdfnd = 0;
if ($hwork=='no')
{

//write log
if ($w_log == 'yes')
{

		if ($msg_type=='groupchat')
		{

		$key = array_search ($from_conf, $bot_nicks);
		if ($key > 0) $bt_nk = $bot_nicks[$key+1];
		else $bt_nk = $bot_nick;
        $chek = substr($pl['body'],0,strlen($bt_nk));
  		if ($chek == $bt_nk)
  		{			{
			$log_msg = "<b>MSG: {$pl['from']}</b><br>".$pl['body']."<br>";
			$fp = fopen ('msg.htm', 'a');
			fwrite ($fp, $log_msg);
			fclose ($fp);
			}
	  	}
	  	}

  		if ($msg_type=='chat')
		{
			$log_msg = "<b>MSG: {$pl['from']}</b><br>".$pl['body']."<br>";
			$fp = fopen ('msg.htm', 'a');
			fwrite ($fp, $log_msg);
			fclose ($fp);
	  	}


}

//send-to-admin-all-messages
if ($allmsg == 'on')
{
		if ($msg_type=='groupchat')
		{
        $chek = substr($pl['body'],0,strlen($bot_nick));
  		if ($chek == $bot_nick) $conn->message($owner.'/', $body=$pl['from'].": ".$pl['body'], $type=$pl['type']);
	  	}

  		if ($msg_type=='chat')
		{
 		$conn->message($owner.'/', $body=$pl['from'].": ".$pl['body'], $type=$pl['type']);
	  	}


}


//CANSORED
$sensor = 'no';
$in_mat = $pl['body'];
$in_mat = strtolower($in_mat);
$in_mat = explode(' ',$pl['body']);
$mat= explode("|", '*figa*|*fuck*|:figa:|:fuck:|figa|fuck|fack you|fuk|shit|хуй|хуи|хуё|хуе|ибать|ипал|соси|аххуен|наху|питб|хуя|ахует|охуел|хуел|охуев|ахуив|пизд|писд|пызд|пысд|пезд|песд|бляд|бля|блад|блят|блать|блйад|блйат|блиад|блиат|ёб|ёп|йоба|аёп|аеб|айоб|аиоб|уёб|уёп|уеб|уиоб|муди|муда|член|члеп|пидор|пидар|гей|нидор|нидар|педи|чмо|жоп|драчи|драцхи|поц|поху|падонак|саси|лох|едритв|пидор|гонд|манд|залуп|суча|сран|мудо|ебаль|сцука');

$matc2 = count($mat);
$matc = count($in_mat);

for($i2=0; $i2<$matc; $i2++)
{
	$chek2 = $in_mat[$i2];


	for($i3=0; $i3<$matc2; $i3++)
	{
	$chek = substr($chek2,0,strlen($mat[$i3]));

		if ($chek == $mat[$i3])
			{
			if (!empty ($chek)) $sensor = 'yes';
			//$conn->message('narkoz@jabber.ru', $body=$chek .' | '. $mat[$i], $type='chat');
			}
			//echo '(('.$mat[$i].'))';
	}

}


if ($sensor == 'yes')
{$wrdfnd = 1;$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FACKYOU'], $type=$msg_type);

if ($msg_type=='groupchat')
		{
        $conn->kick ($from_conf,$from_user,$LANG_OUT['_FACKYOU']);
	  	}
}

if ($say_hi == 'yes')
{
//SAY HI
$sensor2 = 'no';
$in_mat = $pl['body'];
$in_mat = strtolower($in_mat);
$in_mat = explode(' ',$pl['body']);
$mat= explode("|", 'хай|привет|Привет|hi2all|привет|здаров|Здарова|всем привет|превед|здраствуй|добрый день|даров|дароф|:-*|');
$nomat= explode("|", 'Хай-пис-ЙОу! :D|ну что, расказывай )|что нового? |hi|hallo|как жизнь? :)|как дела?|ваууу, какие люди ;))|доброе здоровье|асалямалейкум|проходите, садитесь...|ку|:)|;)|-_-|хари кришна|хари рама|:-*|и тебе|о, ыы )|велком|рад видеть|о! какие люди ;)|смотрите кто пришел :D|кревед))|угу');

$matc2 = count($mat);
$matc = count($in_mat);

for($i2=0; $i2<$matc; $i2++)
{
	$chek2 = $in_mat[$i2];

	for($i3=0; $i3<$matc2; $i3++)
	{
	//$chek = substr($chek2,0,strlen($mat[$i3]));

		if ($chek2 == $mat[$i3])
			{
			if (!empty ($chek2)) $sensor2 = 'yes';
			//$conn->message('narkoz@jabber.ru', $body=$chek .' | '. $mat[$i], $type='chat');
			//echo $chek.'|'.'(('.$mat[$i].'))';
			}
			//echo '(('.$mat[$i].'))';
	}

}


if ($sensor2 == 'yes')
{
$wrdfnd = 1;
$rnd = rand (0, count ($nomat));
$hi_msg = $nomat[$rnd];
$conn->message($from_conf, $body=$from_user.' '.$hi_msg, $type=$msg_type);
}


//SAY BYE
$sensor2 = 'no';
$in_mat = $pl['body'];
$in_mat = strtolower($in_mat);
$in_mat = explode(' ',$pl['body']);
$mat= explode("|", 'пока|поки|всем пока|увидемся|удачи|до скорого|ухожу|уходю|see you|дозавтра|ушёл|');
$nomat= explode("|", 'заходи ;)|заходи не забывай..|bye|будем ждать...|когда будешь? :)|я уже начинаю скучать ((|не покидай меня :(|а как же я :(|будешь проходить мимо - не забывай про нас...|ты куда?|стоять! :D|почему, ещё рано!|ну давай тогда...');

$matc2 = count($mat);
$matc = count($in_mat);

for($i2=0; $i2<$matc; $i2++)
{
	$chek2 = $in_mat[$i2];


	for($i3=0; $i3<$matc2; $i3++)
	{
	//$chek = substr($chek2,0,strlen($mat[$i3]));

		if ($chek2 == $mat[$i3])
			{
			if (!empty ($chek2)) $sensor2 = 'yes';
			//$conn->message('narkoz@jabber.ru', $body=$chek .' | '. $mat[$i], $type='chat');
			//echo $chek.'|'.'(('.$mat[$i].'))';
			}
			//echo '(('.$mat[$i].'))';
	}

}


if ($sensor2 == 'yes')
{
$wrdfnd = 1;
$rnd = rand (0, count ($nomat));
$hi_msg = $nomat[$rnd];
$conn->message($from_conf, $body=$from_user.' '.$hi_msg, $type=$msg_type);
}

}

//--OWNER-UNITS-----------------------------------------------------

//MESSAGE TO ALL CONFERENCE
$in_str = substr($pl['body'],0,8);
if(strtolower($in_str) == 'mass_msg')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$tmp = implode(' ',$arr);
//$tmp = strtolower($tmp);
for($cnf=0 ; $cnf<count($bot_nicks); $cnf++)
{
sleep (1);
if (strlen($bot_nicks[$cnf])>15) $conn->message($bot_nicks[$cnf], $body=$tmp, $type='groupchat');
}
$conn->message($from_conf, $body=$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}

//ADD BOT ADMIN
$in_str = substr($pl['body'],0,9);
if(strtolower($in_str) == 'bot_admin')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
array_push($admins, strtolower($arr[0]));
$tmp = implode('|',$admins);
$fp = fopen ("admin.txt", "w+");
fwrite ($fp, $tmp);
fclose ($fp);
$conn->message($from_conf, $body=$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}

//REMOVE ADMIN
$in_str = substr($pl['body'],0,11);
if(strtolower($in_str) == 'bot_unadmin')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$key = array_search($arr[0], $admins);
if ($key>0)
{
unset ($admins[$key]);
$conn->message($from_conf, $body=$LANG_OUT['_WELLDONE'], $type=$msg_type);
$tmp = implode('|',$admins);
$fp = fopen ("admin.txt", "w+");
fwrite ($fp, $tmp);
fclose ($fp);
}
else
$conn->message($from_conf, $body='Admin not found!', $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}

//ADMIN LIST
$in_str = substr($pl['body'],0,11);
if(strtolower($in_str) == 'bot_admlist')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$tmp = implode('|', $admins);
$conn->message($from_conf, $body=' Admin list: '.$tmp, $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}


//ROLE
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'role')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$tmp = implode('|', $roles);
$conn->message($from_conf, $body=' Role list: '.$tmp, $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}

//TMP PRESENCE
$in_str = substr($pl['body'],0,3);
if(strtolower($in_str) == 'tmp')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$tmp = implode('|', $present);
$conn->message($from_conf, $body=' Present list: '.$tmp, $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}



//ADD TO BAN LIST
$in_str = substr($pl['body'],0,7);
if(strtolower($in_str) == 'jid_ban')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
array_push($ban_list, strtolower($arr[0]));
$tmp = implode('|',$ban_list);
$fp = fopen ("ban.txt", "w+");
fwrite ($fp, $tmp);
fclose ($fp);
$conn->message($from_conf, $body=$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}

//REMOVE FROM BAN LIST
$in_str = substr($pl['body'],0,9);
if(strtolower($in_str) == 'jid_unban')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$key = array_search($arr[0], $ban_list);
if ($key>0)
{
unset ($ban_list[$key]);
$conn->message($from_conf, $body=$LANG_OUT['_WELLDONE'], $type=$msg_type);
$tmp = implode('|',$ban_list);
$fp = fopen ("ban.txt", "w+");
fwrite ($fp, $tmp);
fclose ($fp);
}
else
$conn->message($from_conf, $body='JID not found!', $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}

//BAN LIST
$in_str = substr($pl['body'],0,11);
if(strtolower($in_str) == 'jid_listban')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$tmp = implode('|', $ban_list);
$conn->message($from_conf, $body=' Ban list: '.$tmp, $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}

//status--------------------
$in_str = substr($pl['body'],0,6);
if(strtolower($in_str) == 'status')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$show_text=substr($pl['body'],7);
$conn->presence($show=substr($pl['body'],7), $status=$status_type);
}
else
{
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}
}

//show--------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'show')
{
$wrdfnd = 1;
if ($isowner =='yes')
{
$status_type = substr($pl['body'],5);
$conn->presence($show=$show_text, $status=$status_type);
}
else
{
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FOROWNER'], $type=$msg_type);
}
}



//--ADMIN-UNITS-----------------------------------------------------

//quit----------------------
if(strtolower($pl['body']) == 'quit')
{
if ($isadmin =='yes') $conn->disconnect();
else
{
	$wrdfnd = 1;
	$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'], $type=$msg_type);
}
}

//doReconnect----------------------
if(strtolower($pl['body']) == 'recon')
{
$fr='yes';
$wrdfnd = 1;
if ($isadmin =='yes')
{
//$conn->doReconnect();
$conn->disconnect();
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'], $type=$msg_type);
}

//Quit-all-conference----------------
if(strtolower($pl['body']) == 'confs_out')
{
$hwork='yes';
$wrdfnd = 1;

if ($isadmin =='yes')
{
for($cnf=0 ; $cnf<count($bot_nicks); $cnf++)
{
sleep (1);
if (strlen($bot_nicks[$cnf])>15) $conn->confquit($to=$bot_nicks[$cnf]);
}
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
else
{
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'], $type=$msg_type);
}
$hwork='no';
}

//Join-all-conference----------------
if(strtolower($pl['body']) == 'confs_in')
{
$hwork='yes';
$wrdfnd = 1;
if ($isadmin =='yes')
{
for($cnf=0 ; $cnf<count($bot_nicks); $cnf++)
{
sleep (1);
if (strlen($bot_nicks[$cnf])>15) $conn->joinc($to=$bot_nicks[$cnf].'/'.$bot_nicks[$cnf+1]);
}
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
else
{
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'], $type=$msg_type);
}
$hwork='no';
}

//join conference-----------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'join')
{
$wrdfnd = 1;

if ($isadmin =='yes')
	{
	$arr = explode(" ", $pl['body']);

	//--------------
	$nk_for_join = explode("/", $arr[1]);
	$jconf = $nk_for_join[0];
	$jconf = strtolower($jconf);
	$key = array_search($jconf, $bot_nicks);

    if (strlen ($nk_for_join[1]) > 1)
    {
    if ($key>0)
        {
	        if (strlen ($nk_for_join[1]) < 15 )
    	    {
        	$bot_nicks[$key+1] = $nk_for_join[1];
	        $conn->joinc($to=$jconf.'/'.$nk_for_join[1]);
    	    sleep (1);
       		$tmp = implode('|',$bot_nicks);
			$fp = fopen ("botnick.txt", "w+");
			fwrite ($fp, $tmp);
			fclose ($fp);
			$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
			}
		}
        else
        {

          if (strlen ($nk_for_join[1]) < 15 )
    	    {
			$conn->joinc($to=$jconf.'/'.$nk_for_join[1]);
   			array_push($bot_nicks, $jconf, $nk_for_join[1]);
	        sleep (1);
       		$tmp = implode('|',$bot_nicks);
			$fp = fopen ("botnick.txt", "w+");
			fwrite ($fp, $tmp);
			fclose ($fp);
			$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
			}

        }
    }
    else $conn->message($from_conf, $body=$from_user.' Set nick first!', $type=$msg_type);
	}
	else
		{
		$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'], $type=$msg_type);
		}
}

//conference-remove----------------------------
$in_str = substr($pl['body'],0,11);
if(strtolower($in_str) == 'conf_remove')
{
$wrdfnd = 1;
if ($isadmin =='yes')
{
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$key = array_search($arr[0], $bot_nicks);
if ($key)
{
unset ($bot_nicks[$key]);
unset ($bot_nicks[$key+1]);
//$conn->confquit($to=$bot_nicks[$key]);
$conn->message($from_conf, $body=$LANG_OUT['_WELLDONE'], $type=$msg_type);
$tmp = implode('|',$bot_nicks);
$fp = fopen ("botnick.txt", "w+");
fwrite ($fp, $tmp);
fclose ($fp);
}
else
$conn->message($from_conf, $body='Conference not found!', $type=$msg_type);
}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'], $type=$msg_type);
}


//quit conference
$in_str = substr($pl['body'],0,9);
if(strtolower($in_str) == 'conf_quit')
{

$wrdfnd = 1;
if ($isadmin =='yes')
{

if ($msg_type='chat')
{
	$arr = explode(" ", $pl['body']);
	if (strlen ($arr[1]) > 10)
	{
	$conn->confquit($to=$arr[1]);
	$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
	}
	else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_AD'], $type=$msg_type);

	}


}
else
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'], $type=$msg_type);
}

$in_str = substr($pl['body'],0,5);
if(strtolower($in_str) == 'cquit')
{
$wrdfnd = 1;
//if ($msg_type =='groupchat')
//{
	//$conn->confquit($to=$from_conf);
	if ($ismoder =='yes')
	{
	$conn->confquit($to=$from_conf);
	}
	else
	$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORMODER'], $type=$msg_type);

//}
}


//LANG-SET----------------------------
$in_str = substr($pl['body'],0,8);
if(strtolower($in_str) == 'lang_set')
{

	$wrdfnd = 1;
	//SET LANG BY CONF/USER
	if ($msg_type=='groupchat')
		{
        if ($ismoder == 'yes')
		{

        $key = array_search($from_conf, $all_conf);         // $key = 1;
        if ($key>0)
        {
        if (substr($pl['body'],9) == 'ru') $all_conf[$key+1] ='ru';
		if (substr($pl['body'],9) == 'id') $all_conf[$key+1] ='id';
		if (substr($pl['body'],9) == 'ru2') $all_conf[$key+1] ='ru2';
		if (substr($pl['body'],9) == 'en') $all_conf[$key+1]='en';
		if (substr($pl['body'],9) == 'ua') $all_conf[$key+1]='ua';
		$cnf_lng = implode('|',$all_conf);
		$fp = fopen ("conf.txt", "w+");
		fwrite ($fp, "$cnf_lng");
		fclose ($fp);
        }
        if (substr($pl['body'],9) == 'ru') {array_push($all_conf, $from_conf, "ru"); 	$lang='ru';}
		if (substr($pl['body'],9) == 'id') {array_push($all_conf, $from_conf, "id"); 	$lang='id';}
		if (substr($pl['body'],9) == 'ru2'){array_push($all_conf, $from_conf, "ru2"); $lang='ru2';}
		if (substr($pl['body'],9) == 'en') {array_push($all_conf, $from_conf, "en");  $lang='en';}
		if (substr($pl['body'],9) == 'ua') {array_push($all_conf, $from_conf, "ua");  $lang='ua';}
   		$cnf_lng = implode('|',$all_conf);
		$fp = fopen ("conf.txt", "w+");
		fwrite ($fp, "$cnf_lng");
		fclose ($fp);
	    } else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORMODER'], $type=$msg_type);
	   	}

if ($msg_type=='chat')
		{
        $key = array_search($from_conf, $jid_all_users);
        if ($key>0)
        {
        if (substr($pl['body'],9) == 'ru') $jid_all_users[$key+1] ='ru';
		if (substr($pl['body'],9) == 'id') $jid_all_users[$key+1] ='id';
		if (substr($pl['body'],9) == 'ru2') $jid_all_users[$key+1] ='ru2';
		if (substr($pl['body'],9) == 'en') $jid_all_users[$key+1]='en';
		if (substr($pl['body'],9) == 'ua') $jid_all_users[$key+1]='ua';
		$users_lng = implode('|',$jid_all_users);
		$fp = fopen ("users.txt", "w+");
		fwrite ($fp, $users_lng);
		fclose ($fp);
		}
		else
		{
        if (substr($pl['body'],9) == 'ru') {array_push($jid_all_users, $from_conf, "ru"); 	$lang='ru';}
		if (substr($pl['body'],9) == 'id') {array_push($jid_all_users, $from_conf, "id"); 	$lang='id';}
		if (substr($pl['body'],9) == 'ru2'){array_push($jid_all_users, $from_conf, "ru2"); $lang='ru2';}
		if (substr($pl['body'],9) == 'en') {array_push($jid_all_users, $from_conf, "en");  $lang='en';}
		if (substr($pl['body'],9) == 'ua') {array_push($jid_all_users, $from_conf, "ua");  $lang='ua';}

        if (substr($pl['body'],9) == 'ru') $lang='ru';
		if (substr($pl['body'],9) == 'id') $lang='id';
		if (substr($pl['body'],9) == 'ru2') $lang='ru2';
		if (substr($pl['body'],9) == 'en') $lang='en';
		if (substr($pl['body'],9) == 'ua') $lang='ua';

        $users_lng = implode('|',$jid_all_users);
		$fp = fopen ("users.txt", "w+");
		fwrite ($fp, $users_lng);
		fclose ($fp);
		}


	  	}

if (($msg_type=='chat') || ($ismoder == 'yes'))
{
$Lngerror = 1;
if (substr($pl['body'],9)=='ua')
{
$Lngerror = 0;
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
if (substr($pl['body'],9)=='id')
{
$Lngerror = 0;
 $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
if (substr($pl['body'],9)=='ru')
{
$Lngerror = 0;
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
if (substr($pl['body'],9)=='en')
{
$Lngerror = 0;
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
}
if (substr($pl['body'],9)=='ru2')
{
$Lngerror = 0;
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
}

if ($Lngerror == 1) $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_AD'], $type=$msg_type);

}
}

//Set-nick--------------------
$in_str = substr($pl['body'],0,7);
if(strtolower($in_str) == 'setnick')
{
$hwork='yes';
$wrdfnd = 1;
if ($ismoder == 'yes')
{
	$arr = explode(" ", $pl['body']);
	array_splice($arr, 0, 1);
	$msg_body = implode(' ',$arr);
	$bt_nick = $msg_body;

		if ($msg_type=='groupchat')
		{
		$key = array_search($from_conf, $bot_nicks);
        if ($key>0)
        {
        if (strlen ($bt_nick) < 15 )
        {
           if (strlen ($bt_nick) > 1 )
           {
        	$bot_nicks[$key+1] = $bt_nick;

			$conn->confquit($to=$from_conf);
			sleep (1);
	        $conn->joinc($to=$from_conf.'/'.$bt_nick);
	        sleep (1);
	        $users_lng = implode('|',$bot_nicks);
			$fp = fopen ("botnick.txt", "w+");
			fwrite ($fp, $users_lng);
			fclose ($fp);
			$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
		   }
		   else $conn->message($from_conf, $body=$from_user.' Min. 1 symbol in nickname 8-D', $type=$msg_type);

		}
		else
		{
        $conn->message($from_conf, $body=$from_user.' Max. 15 symbols in nickname 8-D', $type=$msg_type);
		}
		}
	  	}

  		if ($msg_type=='chat')
		{
 		$conn->message($from_conf, $body=$from_user.' Set nick in conference, simple: setnick [nick]', $type=$msg_type);
	  	}

} else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORMODER'], $type=$msg_type);

$hwork='no';
}

//Clear conference------------------
$in_str = substr($pl['body'],0,5);
if(strtolower($in_str) == 'clear')
{
$hwork='yes';
$wrdfnd = 1;
if ($ismoder == 'yes')
{
if ($msg_type=='groupchat')
{
$clear_conf = $from_conf;
for($cl=0 ; $cl<20 ; $cl++ )
{
sleep (2);
$conn->message($clear_conf, $body='.', $type='groupchat');
}
$conn->message($clear_conf, $body=' '. $LANG_OUT['_UCLEAR'], $type='groupchat');
}
else
{
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_UCLEARPRV'], $type=$msg_type);
}
}
else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORMODER'], $type=$msg_type);

$hwork='no';
}

//msg conference------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'msgc')
{if (($isadmin == 'yes') || ($ismoder == 'yes'))
{
$hwork='yes';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
$msg_conf = $arr[1];
array_splice($arr, 0, 2);
$msg_body = implode(' ',$arr);
$conn->message($msg_conf, $body=$msg_body, $type='groupchat');
$hwork='no';
}
else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'].' or '.$LANG_OUT['_FORMODER'] , $type=$msg_type);
}

//msg JID message-----------------
$in_str = substr($pl['body'],0,3);
if(strtolower($in_str) == 'msg')
{
if (($isadmin == 'yes') || ($ismoder == 'yes'))
{
$hwork='yes';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
$msg_jid = $arr[1];
array_splice($arr, 0, 2);
$msg_body = implode(' ',$arr);
$conn->message($msg_jid.'/', $body=$msg_body, $type='chat');
$hwork='no';
}
else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORADMIN'].' or '.$LANG_OUT['_FORMODER'] , $type=$msg_type);
}

//--USER-UNITS--------------------------------------------------------

//PRESENCE LIST
$in_str = substr($pl['body'],0,8);
if(strtolower($in_str) == 'presence')
{
if (($isadmin=='yes') || ($ismoder == 'yes'))
{
$p_nick = '';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
if (strlen ($arr[1])>10)
{
for($i9=0; $i9<count($present); $i9++)
{
$prsnt_cnf = substr ($present[$i9], 0, strlen ($arr[1]));
if ($arr[1] == $prsnt_cnf)
$p_nick = $p_nick .'
'.substr ($present[$i9], strlen ($arr[1]), strlen ($present[$i9]));
}
$p_nick=str_replace('/', '',$p_nick);
if (strlen ($p_nick)<1) $p_nick = $LANG_RU['_GQUERY'];
//$tmp = implode(' ', $present_nicks);
$conn->message($from_conf, $body=' Presence list: '.$p_nick, $type=$msg_type);
}
else
{
	if ($msg_type == 'groupchat')
		{
		    $arr = explode('/', $pl['from']);

			for($i9=0; $i9<count($present); $i9++)
				{
				$prsnt_cnf = substr ($present[$i9], 0, strlen ($arr[0]));
				if ($arr[0] == $prsnt_cnf)
$p_nick = $p_nick .'
'.substr ($present[$i9], strlen ($arr[0]), strlen ($present[$i9]));
				}

		$p_nick=str_replace('/', '',$p_nick);
		if (strlen ($p_nick)<1) $p_nick = $LANG_RU['_GQUERY'];
		$conn->message($from_conf, $body=' Presence list: '.$p_nick, $type=$msg_type);
		}
		else $conn->message($from_conf, $body=$from_user.' Enter correct conference.', $type=$msg_type);

}

} else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORMODER'], $type=$msg_type);

}

//List-all-conference----------------
if(strtolower($pl['body']) == 'clist')
{
if (($isadmin=='yes') || ($ismoder == 'yes'))
{
$hwork='yes';
$wrdfnd = 1;
$list_conf = implode(' ',$bot_nicks);
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_CONFLIST'].$list_conf, $type=$msg_type);
$hwork='no';
}
else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORMODER'], $type=$msg_type);
}


//List-language----------------
if(strtolower($pl['body']) == 'lang_list')
{if (($msg_type=='chat') || ($ismoder == 'yes'))
{
$hwork='yes';
$wrdfnd = 1;
$conn->message($from_conf, $body=$from_user.' '.$LngL, $type=$msg_type);
$hwork='no';
}
else $conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_FORMODER'], $type=$msg_type);
}


//IP-to-DNS-------------------------
$in_str = substr($pl['body'],0,6);
if(strtolower($in_str) == 'ip_dns')
{
$hwork='yes';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);

if (strlen ($msg_body) < 15)
{
$a = gethostbyaddr($msg_body);
}
else
{
$a = ' '.$LANG_OUT['_AD'];
}
$wrdfnd = 1;
$hwork='no';
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_UDOMAIN'].$a, $type=$msg_type);
}




//DNS-to-IP---------------------------
$in_str = substr($pl['body'],0,6);
if(strtolower($in_str) == 'dns_ip')
{
$hwork='yes';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);

if (strlen ($msg_body) < 20)
{
$a = gethostbyname($msg_body);
}
else
{
$a = ' '.$LANG_OUT['_AD'];
}
$wrdfnd = 1;
$hwork='no';
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_UDOMAIN']. $msg_body .' IP: '. $a, $type=$msg_type);
}


//date----------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'date')
{
$wrdfnd = 1;
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_UDATE'] . date("d.m.Y",time()), $type=$msg_type);
}



//gismeteo-pogoda-------------------
$in_str = substr($pl['body'],0,7);
if(strtolower($in_str) == 'weather')
{$hwork='yes';
$wrdfnd = 1;
$c=" ";
$arr = explode(" ", $pl['body']);
$c=$arr[1];
$cit = fread(fopen("city.txt", "r"), filesize("city.txt"));
$bka=explode('|', $cit);
$i = -1;
while(++$i <= count($bka))
 {
$in_str = substr($bka[$i],0,strlen($c));

                if ($in_str == $c)
             {
			$num=$bka[$i-1];
		 }

  }
$c=$num;
$c=(int)$c;
$prov=file("city.txt");
$pr='bad';
for ($i = 0; $i < count($prov); $i++)
{
if(ereg($c, $prov[$i]))$pr='OK';
}
if($pr=='OK'){
$file = file("http://wap.gismeteo.ru/$c.wml");
$file = @implode("", $file);
$file = @explode('<a href', $file);
}
$respage=$file[0];
$respage = substr ($respage, strpos ($respage, "title="), strlen ($respage));
$respage = strip_tags ($respage, '<br><br/>');
$respage=str_replace("<br>", "\n",$respage);
$respage=str_replace("<br/>", "",$respage);
$respage=str_replace("&#176;", "",$respage);
$respage=str_replace('">', '',$respage);
$respage=str_replace('title="', ' '.$LANG_OUT['_UWEATHER'],$respage);
if ($pr == 'bad') $respage = $LANG_OUT['_USITYNOTFND'];
$conn->message($from_conf, $body=$from_user . ' gismeteo.ru '. $respage, $type=$msg_type);
$c=0;
$hwork='no';
}

//BASH----------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'bash')
{$hwork='yes';
$wrdfnd = 1;

if ( ($lang == 'ru') or ($lang == 'ru2') or ($lang == 'ua'))
{
//bash.org.ru----------------------------
$result=file("http://bash.org.ru/random");
$respage=implode($result);
$res1=explode("<body>",$respage);
$respage=$res1[1];
$respage = strip_tags ($respage, '<a><div><br>');
$respage= iconv("CP1251", "UTF-8", $respage);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$respage = substr ($respage, strpos ($respage, "утверждена"), strlen ($respage));
$respage = substr ($respage, strpos ($respage, "<div>"), strlen ($respage));
$respage = substr ($respage, 0, strpos ($respage, "</div>"));
$respage=str_replace('<div>',"",$respage);
$respage=str_replace('<',"\n<",$respage);
$respage=str_replace('<br>',"",$respage);
$respage=str_replace('<br />',"",$respage);
$conn->message($from_conf, $body=$from_user." bash.org.ru: \n" . $respage, $type=$msg_type);
}
else
{//bash.org-------------------------------$result=file("http://bash.org/?random");
$respage=implode($result);
$res1=explode('class="quote"',$respage);
$respage=$res1[1];
$respage= iconv("CP1251", "UTF-8", $respage);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strip_tags ($respage, '<p><br>');
$respage = strtr($respage, $trans);
$respage=str_replace('<br />',"\n",$respage);
$respage=str_replace('</p>',"",$respage);
$respage = substr ($respage, strpos ($respage, 'class="qt">')+11, strlen ($respage));
$conn->message($from_conf, $body=$from_user." bash.org: \n" . $respage, $type=$msg_type);
}
$hwork='no';
}

//GENERAL-HORO-------------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'horo')
{
$hwork='yes';
$wrdfnd = 1;
$tmp = explode (' ', $pl['body']);
$gor_num = $tmp[1];

if (preg_match("#[^0-9]#",$gor_num))
{
$gor_num = 1;
}

if (strlen ($gor_num)< 1)
{
$gor_num = 1;
}


if (($gor_num < 14) and ($gor_num > 0))
{
$result=file("http://www.hyrax.ru/cgi-bin/bn_xml.cgi");
$respage=implode($result);
$respage= iconv("CP1251", "UTF-8", $respage);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strip_tags ($respage, '<item><link>');
$res1=explode('<item>',$respage);
$respage=$res1[$gor_num];
$h1 = substr ($respage, 0, strpos ($respage, '<link>'));
$h2 = substr ($respage, strpos ($respage, '</link>')+7, strlen ($respage));
$respage=$h1.$h2;
$respage=str_replace('</item>',"",$respage);
}
else $respage = ' '.$LANG_OUT['_AD'];

$conn->message($from_conf, $body=$from_user." Общий гороскоп: " . $respage, $type=$msg_type);
$hwork='no';
}

//LOVE-HORO-------------------------------
$in_str = substr($pl['body'],0,5);
if(strtolower($in_str) == 'hlove')
{
$hwork='yes';
$wrdfnd = 1;
$tmp = explode (' ', $pl['body']);
$gor_num = $tmp[1];

if (preg_match("#[^0-9]#",$gor_num))
{
$gor_num = 1;
}

if (strlen ($gor_num)< 1)
{
$gor_num = 1;
}


if (($gor_num < 13) and ($gor_num > 0))
{
$result=file("http://www.hyrax.ru/cgi-bin/love_xml.cgi");
$respage=implode($result);
$respage= iconv("CP1251", "UTF-8", $respage);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strip_tags ($respage, '<item><link>');
$res1=explode('<item>',$respage);
$respage=$res1[$gor_num];
$h1 = substr ($respage, 0, strpos ($respage, '<link>'));
$h2 = substr ($respage, strpos ($respage, '</link>')+7, strlen ($respage));
$respage=$h1.$h2;
$respage=str_replace('</item>',"",$respage);
}
else $respage = ' '.$LANG_OUT['_AD'];

$conn->message($from_conf, $body=$from_user." Любовный гороскоп: " . $respage, $type=$msg_type);
$hwork='no';
}



//news----------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'news')
{$wrdfnd = 1;
$hwork='yes';
$nnws="1";
$arr = explode(" ", $pl['body']);
if ($arr[1] != '') $nnws=$arr[1];

$result=file("http://www.podrobnosti.ua/rss");
$respage=implode($result);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$res1=explode("<channel>",$respage);
$respage=$res1[1];
$respage = strip_tags ($respage, '<item><description><title><link>');
$respage= iconv("CP1251", "UTF-8", $respage);
$res3=explode("<item>",$respage);

if (preg_match("#[^0-9]#",$arr[1]))
{
$respage = ' '.$LANG_OUT['_AD'];
}
else
{
if ($nnws < 11) $respage=$res3[$nnws]; else $respage = ' '.$LANG_OUT['_AD'];
}

$respage=str_replace('</title>','',$respage);
$respage=str_replace('</link>','',$respage);
$respage=str_replace('</description>','',$respage);
$respage=str_replace('<description>','',$respage);
$respage=str_replace('<title>','',$respage);
$respage=str_replace('<link>','',$respage);
$respage=str_replace('<pubDate>','',$respage);
$respage=str_replace('</pubDate>','',$respage);
$respage=str_replace('</item>','',$respage);

	$conn->message($from_conf, $body=$from_user.$LANG_OUT['_UNEWS']. $respage, $type=$msg_type);
$hwork='no';
}

//google-wap---------------------------
$in_str = substr($pl['body'],0,3);
if(strtolower($in_str) == 'wap')
{$wrdfnd = 1;
$hwork='yes';
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);

$q = $msg_body;
if(empty($q)){echo"google none";
}else{
$q=urlencode($q);
$result=file("http://www.google.ru/xhtml/search?q=$q&site=mobile&start=$start");
$respage=implode($result);
$res1=explode("<body>",$respage);
$respage=$res1[1];
$respage = strip_tags ($respage, '<a>');
$respage=str_replace('',"",$respage);
$respage = substr ($respage, strpos ($respage, "WAP"), strlen ($respage));
$respage = substr ($respage, 0, strpos ($respage, "</a>"));
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$respage = substr ($respage, strpos ($respage, '<a href=')+9, strlen ($respage));
$lnk = substr ($respage, 0,strpos ($respage, '">'));
//$lnk = substr ($respage, strpos ($lnk, '<a href="'),strpos ($lnk, '">'));
$gbod = substr ($respage, strpos ($respage, '>')+1, strlen ($respage));
$respage = $LANG_OUT['_GDESCRIPT'].$gbod.'
'.$LANG_OUT['_GLINK'].$lnk;
$hlink = substr($lnk,0,4);
if ($hlink != 'http') $respage = ' '. $LANG_OUT['_GQUERY']; else $respage = $respage;

	$conn->message($from_conf, $body=$from_user." ".$respage, $type=$msg_type);
	}
$hwork='no';
}


//google-web---------------------------
$in_str = substr($pl['body'],0,6);
if(strtolower($in_str) == 'google')
{
$wrdfnd = 1;
$hwork='yes';
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);

$q = $msg_body;
if(empty($q)){echo"google none";
}else{
$gansver_ok = 'yes';
$q=urlencode($q);
$result=file("http://www.google.ru/search?q=$q");
$respage=implode($result);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$respage= iconv("CP1251", "UTF-8", $respage);
$gtitle = substr ($respage, strpos ($respage, 'class=l')+8, strlen ($respage));
$gtitle = substr ($gtitle, 0, strpos ($gtitle, '<table'));
$gtitle = strip_tags ($gtitle, '');
if (strpos ($respage, '<td class=j>') > 1) $gansver_ok = 'no';
$respage = substr ($respage, strpos ($respage, '<div class=std>')+15, strlen ($respage));
$deskript = substr ($respage, 0, strpos ($respage, '<span class=a>')+14);
$deskript = strip_tags ($deskript, '');
$respage = substr ($respage, strpos ($respage, '<span class=a>')+14, strlen ($respage));
$glink = substr ($respage, 0, strpos ($respage, '</span>'));
$deskript=str_replace('<b>','',$deskript);
$deskript=str_replace('</b>','',$deskript);
$deskript=str_replace('<br>',' ',$deskript); ///new
$deskript=str_replace('<span class=a>','',$deskript);
$gtitle=str_replace('[ Перевести эту страницу ]','',$gtitle);
$glink = strip_tags ($glink, '');

if ($gansver_ok == 'yes')
{
$conn->message($from_conf, $body=$from_user.' '.$gtitle.'|'.$deskript.' http://'.$glink, $type=$msg_type);
}
else
{
$respage = $LANG_OUT['_GQUERY'];
$conn->message($from_conf, $body=$from_user.' '.$respage, $type=$msg_type);
}
$hwork='no';
}
}


//google-translate---------------------------
$in_str = substr($pl['body'],0,2);
if(strtolower($in_str) == 'tr')
{
$wrdfnd = 1;
$hwork='yes';
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$tr_type = $arr[0];
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);
$q = $msg_body;
$tr_type_all = ' en|ru ru|en en|es es|en en|it it|en en|de de|en en|fr fr|en';
$pos = strpos($tr_type_all, $tr_type);
echo $pos;
if ($pos>0)
{
//nothing
}
else
{
$q=$tr_type.' '.$msg_body;
$tr_type = 'en|ru';
}
if(empty($q)){echo'translate none';}else{
$q= iconv("UTF-8", "CP1251", $q);
$q=urlencode($q);
$result=file("http://translate.google.com/translate_t?langpair=$tr_type&text=$q");
$respage=implode($result);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$respage= iconv("CP1251", "UTF-8", $respage);
$respage = substr ($respage, strpos ($respage, "result_box dir"), strlen ($respage));
$respage = substr ($respage, 0, strpos ($respage, "</div>"));
$respage = substr ($respage, strpos ($respage, ">")+1, strlen ($respage));
$respage= iconv("UTF-8", "CP1251", $respage);
$respage= iconv("KOI8-U", "CP1251", $respage);
$respage= iconv("CP1251", "UTF-8", $respage);
if ($respage == '') $respage = 'Sorry, error ((';
$conn->message($from_conf, $body=$from_user." ".$respage, $type=$msg_type);
}
$hwork='no';
}



//ostrie ----------------------------------------
$in_str = substr($pl['body'],0,6);
if(strtolower($in_str) == 'ostrie')
{
$wrdfnd = 1;
$hwork='yes';
$nnws="1";
$arr = explode(" ", $pl['body']);
if ($arr[1] != '') $nnws=$arr[1];
$result=file("http://ostrie.moskva.com/rss/");
$respage=implode($result);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$res1=explode("<channel>",$respage);
$respage=$res1[1];
$respage = strip_tags ($respage, '<item><description><link>');
$respage= iconv("CP1251", "UTF-8", $respage);
$respage= iconv("UTF-8", "CP1251", $respage);
$respage= iconv("KOI8-U", "CP1251", $respage);
$respage= iconv("CP1251", "UTF-8", $respage);
$res3=explode("<item>",$respage);

$respage=$res3[$nnws];
$link1=substr ($respage, strpos ($respage, '<link>')+6, strlen ($respage));
$link1=substr ($link1, 0, strpos ($link1, '</link>'));

$tmp1=explode("<description>",$respage);
$deskript1=$tmp1[1];
$deskript1=str_replace('</item>','',$deskript1);
$deskript1=str_replace('</description>','',$deskript1);
$deskript1=substr ($deskript1, 0, strlen ($deskript1)-4);

if (preg_match("#[^0-9]#",$arr[1]))
{
$respage = ' '.$LANG_OUT['_AD'];
}
else
{
if ($nnws < 11) $respage = $deskript1.'
'.$link1;
 else $respage = ' '.$LANG_OUT['_AD'];
}

$conn->message($from_conf, $body=$from_user.' Ostrie: '. $respage, $type=$msg_type);
$hwork='no';
}

//WHOIS---------------------------------------
$in_str = substr($pl['body'],0,5);
if(strtolower($in_str) == 'whois')
{
$wrdfnd = 1;
$hwork='yes';
$nnws="1";
$arr = explode(" ", $pl['body']);
//if ($arr[1] != '') $nnws=$arr[1];
$result=file("http://centralops.net/co/DomainDossier.aspx?addr=$arr[1]&dom_whois=1");
$respage=implode($result);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$respage=substr ($respage, strpos ($respage, '<h3>Domain Whois record</h3>'), strlen ($respage));
$respage = strip_tags ($respage, '<b>');
$respage=substr ($respage, 0, strpos ($respage, 'MSK/MSD'));
$respage=str_replace('<b>',' ',$respage);
$respage=str_replace('</b>','
',$respage);
$respage=str_replace('		','',$respage);
$conn->message($from_conf, $body=$from_user.' '. $respage, $type=$msg_type);
$hwork='no';
}

//SCAN-IP---------------------------------------
$in_str = substr($pl['body'],0,7);
if(strtolower($in_str) == 'scan_ip')
{
$wrdfnd = 1;
$hwork='yes';
$nnws="1";
$arr = explode(" ", $pl['body']);
//if ($arr[1] != '') $nnws=$arr[1];
$result=file("http://centralops.net/co/DomainDossier.aspx?addr=$arr[1]&svc_scan=1");
$respage=implode($result);
$trans = get_html_translation_table(HTML_ENTITIES);
$trans = array_flip($trans);
$respage = strtr($respage, $trans);
$respage=substr ($respage, strpos ($respage, '<h3>Service scan</h3>'), strlen ($respage));
$respage = strip_tags ($respage, '<b>');
$respage=substr ($respage, 0, strpos ($respage, '-- end --'));
$respage=str_replace('<b>',' ',$respage);
$respage=str_replace('</b>','
',$respage);
$respage=str_replace('		','',$respage);
$conn->message($from_conf, $body=$from_user.' '. $respage, $type=$msg_type);
$hwork='no';
}


//SMS-------------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'sms ')
{
$nnws="1";
$wrdfnd = 1;
$in_arr = explode("/", $pl['from']);

$key = array_search($in_arr[0], $no_spamm);
if ($key > 0)
{
if ($no_spamm[$key+1] < 10) $spam_ok = true; else $spam_ok = false;
}
else
{
array_push ($no_spamm, $in_arr[0], 0);
$spam_ok = true;
}

	if ($spam_ok)
	{
	$tmp = explode (' ', $pl['body']);
	$sms_numb = $tmp[1];
		if ((strlen ($sms_numb) > 10) and (strlen ($sms_numb) < 13))
		{
		$key = 0;
		$sms_numb=str_replace("+", "",$sms_numb);
		array_splice($tmp, 0, 2);
		$sms_body = implode ('%20', $tmp);
		$sms_body= iconv("UTF-8", "CP1251", $sms_body);

		for($sb=0; $sb<count ($sms_gate_base); $sb++)
			{
			$tmp_numb = substr($sms_numb,0,strlen ($sms_gate_base[$sb]));
			if ($tmp_numb == $sms_gate_base[$sb]) $key = $sb;
			}

			//$key = array_search($tmp_numb, $sms_gate_base);
			if ($key>0)
			{
			$sms_mail = $sms_numb.'@'.$sms_gate_base[$key+1];
			$result=file("http://mastbe.uzelok.net/simple_mail.php?mail_to=$sms_mail&mail_msg=$sms_body");
			$conn->message($from_conf, $body=$from_user.' '.$result[0], $type=$msg_type);
        	$key = array_search($from_conf, $no_spamm);
			$sms_cols = $no_spamm[$key+1];
			$sms_cols++;
			$no_spamm[$key+1] = $sms_cols;
			}
		     else $conn->message($from_conf, $body=$from_user." Этот оператор отсутствует в базе :(", $type=$msg_type);


		} else $conn->message($from_conf, $body=$from_user." Используйте правильный формат, например: 380971234567", $type=$msg_type);

	} else $conn->message($from_conf, $body=$from_user." Превышен лимит сообщений! *STOP*", $type=$msg_type);


}

//SMS PREFIX LIST
$in_str = substr($pl['body'],0,6);
if(strtolower($in_str) == 'smspfx')
{
$nnws="1";
$wrdfnd = 1;
for($xx=0; $xx<count ($sms_gate_base); $xx++)
{array_push ($sms_pfx, $sms_gate_base[$xx+1]);
}

$conn->message($from_conf, $body=' SMS prefix list: '.implode ('|',$sms_gate_base), $type=$msg_type);
}

//time----------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'time')
{
$hwork='yes';
$wrdfnd = 1;
	$conn->message($from_conf, $body=$from_user.' '. $LANG_OUT['_UTIME'] . date("H:i",time()), $type=$msg_type);
$hwork='no';
}

//PING----------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'ping')
{
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
//$msg_body = implode(' ',$arr);


$hwork='yes';
$wrdfnd = 1;

if ($msg_type == 'chat')
{
$conn->vinfo($from_conf, $from_conf, $msg_type, 'ping');

}

if ($msg_type == 'groupchat')
{
$f_jid = '';
if (strlen ($arr[0]) > 0)
{
$key = array_search($from_conf.'/'.$arr[0], $roles);
if ($key>0)
{
$f_jid = $roles[$key+1];
}

}
else
{
$arr = explode("/", $pl['from']);
$key = array_search($from_conf.'/'.$arr[1], $roles);
if ($key>0)
{
$f_jid = $roles[$key+1];
}
}

if (strlen ($f_jid) > 0)
{
$conn->vinfo2($f_jid, $f_jid, $from_conf, $msg_type, 'ping');
}
else $conn->message($from_conf, $body='Give me admin, or JID not found!', $type=$msg_type);
//$cbot_jid_nick.'@'.$cbot_jid_server.'/'.$cbot_jid_resource
//$conn->message($from_conf, $body='|'.$f_jid.'|', $type=$msg_type);
}

$hwork='no';
}

//version----------------------------
$in_str = substr($pl['body'],0,7);
if(strtolower($in_str) == 'version')
{$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
//$msg_body = implode(' ',$arr);


$hwork='yes';
$wrdfnd = 1;

if ($msg_type == 'chat')
{
$conn->vinfo($from_conf, $from_conf, $msg_type, 'ver');
}

if ($msg_type == 'groupchat')
{
$f_jid = '';
if (strlen ($arr[0]) > 0)
{
$key = array_search($from_conf.'/'.$arr[0], $roles);
if ($key>0)
{
$f_jid = $roles[$key+1];
}

}
else
{$arr = explode("/", $pl['from']);
$key = array_search($from_conf.'/'.$arr[1], $roles);
if ($key>0)
{
$f_jid = $roles[$key+1];
}
}

if (strlen ($f_jid) > 0)
{
$conn->vinfo2($f_jid, $f_jid, $from_conf, $msg_type, 'ver');
}
else $conn->message($from_conf, $body='Give me admin, or JID not found!', $type=$msg_type);
//$cbot_jid_nick.'@'.$cbot_jid_server.'/'.$cbot_jid_resource
//$conn->message($from_conf, $body='|'.$f_jid.'|', $type=$msg_type);
}

$hwork='no';
}

//about----------------------------
$in_str = substr($pl['body'],0,7);
if(strtolower($in_str) == 'about')
{
$hwork='yes';
$wrdfnd = 1;
$v=phpversion().' '.$_SERVER['SERVER_SOFTWARE'];
$conn->message($from_conf, $body=$from_user." Cool Bot 1.5.2 by NarKoZ@jabber.ru, PHP:".$v, $type=$msg_type);
$hwork='no';
}

//calc----------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'calc')
{$hwork='yes';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);

if (preg_match('#[^0123456789-+*/)(]#',$msg_body))
{
$a = ' '.$LANG_OUT['_AD'];
}
else
{
if (strlen ($msg_body) < 12)
{
$a = eval("return $msg_body;");
}
else
{$a = ' '.$LANG_OUT['_AD'];
}
}
$wrdfnd = 1;
$hwork='no';
$conn->message($from_conf, $body=$from_user.' ' . $a, $type=$msg_type);

}


//Password-gen--------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'pass')
{
$hwork='yes';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);

if (preg_match("#[^0-9]#",$msg_body))
{
$a = ' '.$LANG_OUT['_AD'];
}
else
{
if ($msg_body < 21)
{
if ($msg_body < 1) $msg_body = 10;
$a = genPwd($msg_body);
}
else $a=$LANG_OUT['_UMAXLEN'];

}
$wrdfnd = 1;
$hwork='no';
$conn->message($from_conf, $body=$from_user.$LANG_OUT['_UPASS']. $a, $type=$msg_type);

}

//help----------------------------
$in_str = substr($pl['body'],0,4);
if(strtolower($in_str) == 'help')
{
$hwork='yes';
$wrdfnd = 1;
$help_info = ' ';
$hlp = strtolower($pl['body']);
if ($hlp == 'help lang_set') $help_info = $LANG_OUT['_HLSET'];
if ($hlp == 'help lang_list') $help_info = $LANG_OUT['_HLL'];
if ($hlp == 'help status') $help_info = $LANG_OUT['_HSTATUS'];
if ($hlp == 'help dns_ip') $help_info = $LANG_OUT['_HDNSIP'];
if ($hlp == 'help clist') $help_info = $LANG_OUT['_HCLIST'];
if ($hlp == 'help confs_in') $help_info = $LANG_OUT['_HCONFIN'];
if ($hlp == 'help confs_out') $help_info = $LANG_OUT['_HCONFOUT'];
if ($hlp == 'help presence') $help_info = $LANG_OUT['_HPRESENT'];
if ($hlp == 'help setnick') $help_info = $LANG_OUT['_HSETNICK'];
if ($hlp == 'help pass') $help_info = $LANG_OUT['_HPASS'];
if ($hlp == 'help clear') $help_info = $LANG_OUT['_HCLEAR'];
if ($hlp == 'help recon') $help_info = $LANG_OUT['_HRECON'];
if ($hlp == 'help join') $help_info = $LANG_OUT['_HJOIN'];
if ($hlp == 'help quit') $help_info = $LANG_OUT['_HQUIT'];
if ($hlp == 'help cquit') $help_info = $LANG_OUT['_HCQUIT'];
if ($hlp == 'help conf_quit') $help_info = $LANG_OUT['_HCONFQUIT'];
if ($hlp == 'help admin') $help_info = $LANG_OUT['_HADMIN'];
if ($hlp == 'help moder') $help_info = $LANG_OUT['_HMODER'];
if ($hlp == 'help user') $help_info = $LANG_OUT['_HUSER'];
if ($hlp == 'help owner') $help_info = $LANG_OUT['_HOWNER'];
if ($hlp == 'help bug') $help_info = $LANG_OUT['_HBUG'];
if ($hlp == 'help calc') $help_info = $LANG_OUT['_HCALC'];
if ($hlp == 'help date') $help_info = $LANG_OUT['_HDATE'];
if ($hlp == 'help ping') $help_info = $LANG_OUT['_HPING'];
if ($hlp == 'help version') $help_info = $LANG_OUT['_HVERSION'];
if ($hlp == 'help time') $help_info = $LANG_OUT['_HTIME'];
if ($hlp == 'help conf_remove') $help_info = $LANG_OUT['_HCREMOVE'];
if ($hlp == 'help add') $help_info = $LANG_OUT['_HADD'];
if ($hlp == 'help tr') $help_info = $LANG_OUT['_HTR'];
if ($hlp == 'help tr_list') $help_info = $LANG_OUT['_HTRLIST'];
if ($hlp == 'help msg') $help_info = $LANG_OUT['_HMSG'];
if ($hlp == 'help msgc') $help_info = $LANG_OUT['_HMSGC'];
if ($hlp == 'help internet') $help_info = $LANG_OUT['_HINET'];
if ($hlp == 'help google') $help_info = $LANG_OUT['_HIGOOGLE'];
if ($hlp == 'help wap') $help_info = $LANG_OUT['_HIGWAP'];
if ($hlp == 'help bash') $help_info = $LANG_OUT['_HIBASH'];
if ($hlp == 'help whois') $help_info = $LANG_OUT['_HWHOIS'];
if ($hlp == 'help news') $help_info = $LANG_OUT['_HINEWS'];
if ($hlp == 'help horo') $help_info = $LANG_OUT['_HHORO'];
if ($hlp == 'help hlove') $help_info = $LANG_OUT['_HHLOVE'];
if ($hlp == 'help weather') $help_info = $LANG_OUT['_HIWEATHER'];
if ($hlp == 'help about') $help_info = $LANG_OUT['_HABOUT'];
if ($hlp == 'help') $help_info = $LANG_OUT['_HHELP'];
if ($hlp == 'help sms') $help_info = $LANG_OUT['_HSMS'];
if ($hlp == 'help scan_ip') $help_info = $LANG_OUT['_HSCANIP'];
if (strlen($help_info) < 2 ) $help_info = $LANG_OUT['_HNOTFND'];
$conn->message($from_conf, $body=' '.$help_info, $type=$msg_type);
$hwork='no';
}

//bug-message-------(msg for admin)
$in_str = substr($pl['body'],0,3);
if(strtolower($in_str) == 'bug')
{$hwork='yes';
$wrdfnd = 1;
$arr = explode(" ", $pl['body']);
array_splice($arr, 0, 1);
$msg_body = implode(' ',$arr);
$conn->message($owner.'/', $body=$pl['from'].": ".$msg_body, $type='chat');
$hwork='no';
}

//auto-add-on----------------------
$in_str = substr($pl['body'],0,7);
if(strtolower($in_str) == 'auto on')
{$hwork='yes';
$wrdfnd = 1;
$auto ='on';
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_UMINDON'], $type=$msg_type);
$hwork='no';
}

//auto-add-off----------------------
$in_str = substr($pl['body'],0,8);
if(strtolower($in_str) == 'auto off')
{
$hwork='yes';
$auto ='off';
$wrdfnd = 1;
$conn->message($from_conf, $body=$from_user.' '.$LANG_OUT['_UMINDOFF'], $type=$msg_type);
$hwork='no';
}

//auto-add-------------------
$in_str = substr($pl['body'],0,3);
if($auto == 'on')
{$hwork='yes';
$wrdfnd = 1;

$text=$pl['body'];
$arr = explode(" ", $text);
$add_str = $arr[1];
array_splice($arr, 0, 1);
$add_text = implode(' ',$arr);
$b_data = "data.txt";
$data = fopen($b_data, "a");
fwrite($data, "$add_str|$add_text|");
fclose($data);
$hwork='no';
}

//add text value-------------------
$in_str = substr($pl['body'],0,3);
if(strtolower($in_str) == 'add')
{$wrdfnd = 1;$hwork='yes';
$arr = explode(' ', $pl['body']);
$add_str = $arr[1];
$add_text = $arr[2];
$data = "data.txt";
$data = fopen($data, "a");
fwrite($data, "$add_str|$add_text|");
fclose($data);
$conn->message($from_conf, $body=' '.$LANG_OUT['_WELLDONE'], $type=$msg_type);
$hwork='no';
}

$in_messages++;
if ($in_messages > 100+rand (0, 50))
{$wrdfnd == 0;
$in_messages = 0;}

//BASE-ANSVERS----------------------------
if ($wrdfnd == 0)
{
$in_txt=$pl['body'];
$in_txt = str_replace(" ", "_", $in_txt);

$counter = count ($stat_arr);
$i = -2;
while(++$i <= $counter)
{
$hwork='yes';
$in_str = substr($stat_arr[$i],0,strlen($in_txt));
//$pos = strpos($pl['from'], "conference");
//if ($pos>1)  $msg_type="groupchat"; else $msg_type='chat';

$key = array_search($from_conf, $bot_nicks);
if ($key>0)
   {
   $bot_nick2 = $bot_nicks[$key+1];
   }
   else
   {
   $bot_nick2 = $bot_nick;
   }

if ($msg_type=='chat')
{
$bot_nick2 = str_replace($bot_nick,'',$bot_nick2);
$res = $in_str;
$from_user = '';
}

if ($msg_type=='groupchat')
{

$res = $bot_nick2 . ":_" . $in_str;
//$res2 = $bot_nick2 . ":_" . $in_str;
}
//echo ("|res:" . $res . "|res2:" . $res2 . "|intxt:" . $in_txt);
if ($res == $in_txt)
	{
	$counter = 0;
	$wrdfnd = 1;
	$out_txt = str_replace("_", " ", $stat_arr[$i+1]);
	$conn->message($from_conf, $body=$from_user." ".$out_txt, $type=$msg_type);
	}
$hwork='no';
}
}

//RANDOM ANSVERS
if ($wrdfnd == 0)
{
//$bot_nick2 = $bot_nick;
if ($msg_type=='chat')
{
$bot_nick2 = str_replace($bot_nick,'',$bot_nick2);
$from_user = '';
//$stat_arr = array();
//$readdata = fopen("data.txt", "rb");
//$x = fread($readdata, filesize("data.txt"));
$rand_num = rand(1, 4);
if ($rand_num = 1) $stat_arr2 = explode("<QUESTION>", $x2);
if ($rand_num = 2) $stat_arr2 = explode("<IGNORED>", $x2);
if ($rand_num = 3) $stat_arr2 = explode("<ESCAPE>", $x2);
if ($rand_num = 4) $stat_arr2 = explode("<THOUGHT>", $x2);
//if ($rand_num = 5) $stat_arr2 = explode("<INITIAL>", $x2);
//fclose($readdata);
$counter = count ($stat_arr2);
$out_txt = str_replace("_", " ", $stat_arr2[rand(1, $counter)]);
$conn->message($from_conf, $body=$from_user." ".$out_txt, $type=$msg_type);
}

if ($msg_type=='groupchat')
{
$res = $bot_nick2 . ":";
$body_nick2 = substr($pl['body'],0,strlen ($bot_nick2)+1);
if ($res == $body_nick2)
	{//$stat_arr2 = array();
//$readdata = fopen("data.txt", "rb");
//$x = fread($readdata, filesize("data.txt"));
$rand_num = rand(1, 4);
if ($rand_num = 1) $stat_arr2 = explode("<QUESTION>", $x2);
if ($rand_num = 2) $stat_arr2 = explode("<IGNORED>", $x2);
if ($rand_num = 3) $stat_arr2 = explode("<ESCAPE>", $x2);
if ($rand_num = 4) $stat_arr2 = explode("<THOUGHT>", $x2);
//if ($rand_num = 5) $stat_arr2 = explode("<INITIAL>", $x2);
//fclose($readdata);
$counter = count ($stat_arr);
$out_txt = str_replace("_", " ", $stat_arr[rand(1, $counter)]);
$conn->message($from_conf, $body=$from_user." ".$out_txt, $type=$msg_type);

	}
}

}

}


}
//else $conn->message($from_conf, $body=$from_user." Я с тобой не разговариваю.", $type=$msg_type);
//if($pl['body'] == 'break') $conn->send("</end>");

break;

case 'presence':
$roles = $conn->r1;
array_unshift($roles, ' ');

$present = array ();
for($z=0 ; $z<count($roles); $z++)
{$key = strpos ($roles[$z], 'conference');
if ($key>0) array_push ($present, $roles[$z]);}
array_unshift($present, ' ');

//print "Presence: {$pl['from']} [{$pl['jid']}] {$pl['role']}<p>\n";

//print_r ($conn->r1);
//$conn->message('narkoz@localhost', $body=$conn->role_list['from'].$conn->role_list['jid'].$conn->role_list['role'], $type=$msg_type);

break;

case 'session_start':
			//autoconnect-conferences
			if ($fr == 'yes')
			{
            for($cnf=0 ; $cnf<count($bot_nicks); $cnf++)
				{
				//sleep (1);
                if (strlen($bot_nicks[$cnf])>15) $conn->joinc($to=$bot_nicks[$cnf].'/'.$bot_nicks[$cnf+1]);
				}

			$fr='no';
			}
				$conn->presence($show=$show_text, $status=$status_type);

break;
		}
	}
}

?>
